package com.example.demo.service.Impl;


import com.example.demo.dao.IUser;
import com.example.demo.model.User;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator 高欣月
 */

@Service
public class UserServiceImpl implements IUserService{

    @Autowired
    private IUser userMapper;
    @Override
    public int insertUser(User user){
        int userValue=0;

       User user1=new User();
        user1.setName(user.getName());
        List<User> getU=userMapper.getAllUser(user1);
        if(getU.size()>=1){
            userValue=-1;

        }else{
            userValue=userMapper.insertUser(user);
        }

        return userValue;
    }

    @Override
    public List<User> getAllUser(User user) {


        return userMapper.getAllUser(user);
    }

    @Override
    public int updateUser(User user) {
        int userValues=0;
        if(user.getYgid()!=0){



            userValues=userMapper.updateUser(user);
        }
        return userValues;
    }

    @Override
    public int deleteUser(User user) {
        int userValues=0;
        if(user.getYgid()!=0)
        {
            //主键是否与其他表有关联

           userValues=userMapper.deleteUser(user);
        }
        return userValues;
    }

    @Override
    public User getUser(User user) {
        User user1=new User();
        if(user.getYgid()!=0){
            user1=userMapper.getUser(user);
        }
        return user1;
    }

}
